package com.suse.service.community.entity;

import java.io.Serializable;
import java.util.Date;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 登录凭证
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-29
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="LoginTicket", description="登录凭证")
public class LoginTicket implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;

    private Integer userId;

    private String ticket;

    @ApiModelProperty(value = "0-无效; 1-有效;")
    private Integer status;

    private Date expired;

    /**
     * 判断登录凭证是否有效
     * @return 登录凭证是否有效
     */
    public boolean isValid() {
        if (ObjectUtil.isNull(status) || ObjectUtil.isNull(expired)) {
            return false;
        }
        return status == 1 && new Date().before(expired);
    }

}
